﻿using System;
using System.ComponentModel;
using System.IO;
using System.Runtime.Serialization;

namespace HalconDotNet
{
	/// <summary>Represents an instance of a texture model for texture inspection.</summary>
	// Token: 0x0200006D RID: 109
	[Serializable]
	public class HTextureInspectionModel : HHandle, ISerializable, ICloneable
	{
		// Token: 0x06001912 RID: 6418 RVA: 0x0000883B File Offset: 0x00006A3B
		[EditorBrowsable(EditorBrowsableState.Never)]
		public HTextureInspectionModel() : base(HHandleBase.UNDEF)
		{
		}

		// Token: 0x06001913 RID: 6419 RVA: 0x0009FB90 File Offset: 0x0009DD90
		[EditorBrowsable(EditorBrowsableState.Never)]
		public HTextureInspectionModel(IntPtr handle) : base(handle)
		{
			this.AssertSemType();
		}

		// Token: 0x06001914 RID: 6420 RVA: 0x0009FB9F File Offset: 0x0009DD9F
		[EditorBrowsable(EditorBrowsableState.Never)]
		public HTextureInspectionModel(HHandle handle) : base(handle)
		{
			this.AssertSemType();
		}

		// Token: 0x06001915 RID: 6421 RVA: 0x0009FBAE File Offset: 0x0009DDAE
		private void AssertSemType()
		{
			base.AssertSemType("texture_inspection_model");
		}

		// Token: 0x06001916 RID: 6422 RVA: 0x0009FBBB File Offset: 0x0009DDBB
		internal static int LoadNew(IntPtr proc, int parIndex, int err, out HTextureInspectionModel obj)
		{
			obj = new HTextureInspectionModel(HHandleBase.UNDEF);
			return obj.Load(proc, parIndex, err);
		}

		// Token: 0x06001917 RID: 6423 RVA: 0x0009FBD4 File Offset: 0x0009DDD4
		internal static int LoadNew(IntPtr proc, int parIndex, int err, out HTextureInspectionModel[] obj)
		{
			HTuple htuple;
			err = HTuple.LoadNew(proc, parIndex, err, out htuple);
			obj = new HTextureInspectionModel[htuple.Length];
			for (int i = 0; i < htuple.Length; i++)
			{
				obj[i] = new HTextureInspectionModel(HalconAPI.IsLegacyHandleMode() ? htuple[i].IP : htuple[i].H);
			}
			htuple.Dispose();
			return err;
		}

		/// <summary>
		///   Create a texture inspection model.
		///   Modified instance represents: Handle for using and accessing the texture inspection model.
		/// </summary>
		/// <param name="modelType">The type of the created texture inspection model. Default: "basic"</param>
		// Token: 0x06001918 RID: 6424 RVA: 0x0009FC44 File Offset: 0x0009DE44
		public HTextureInspectionModel(string modelType)
		{
			IntPtr proc = HalconAPI.PreCall(2051);
			HalconAPI.StoreS(proc, 0, modelType);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			num = base.Load(proc, 0, num);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
		}

		// Token: 0x06001919 RID: 6425 RVA: 0x0009FC90 File Offset: 0x0009DE90
		void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
		{
			HSerializedItem hserializedItem = this.SerializeTextureInspectionModel();
			byte[] value = hserializedItem;
			hserializedItem.Dispose();
			info.AddValue("data", value, typeof(byte[]));
		}

		// Token: 0x0600191A RID: 6426 RVA: 0x0009FCC8 File Offset: 0x0009DEC8
		[EditorBrowsable(EditorBrowsableState.Never)]
		public HTextureInspectionModel(SerializationInfo info, StreamingContext context)
		{
			HSerializedItem hserializedItem = new HSerializedItem((byte[])info.GetValue("data", typeof(byte[])));
			this.DeserializeTextureInspectionModel(hserializedItem);
			hserializedItem.Dispose();
		}

		/// <summary>Serialize object to binary stream in HALCON format</summary>
		// Token: 0x0600191B RID: 6427 RVA: 0x0009FD08 File Offset: 0x0009DF08
		public new void Serialize(Stream stream)
		{
			HSerializedItem hserializedItem = this.SerializeTextureInspectionModel();
			hserializedItem.Serialize(stream);
			hserializedItem.Dispose();
		}

		/// <summary>Deserialize object from binary stream in HALCON format</summary>
		// Token: 0x0600191C RID: 6428 RVA: 0x0009FD1C File Offset: 0x0009DF1C
		public new static HTextureInspectionModel Deserialize(Stream stream)
		{
			HTextureInspectionModel htextureInspectionModel = new HTextureInspectionModel();
			HSerializedItem hserializedItem = HSerializedItem.Deserialize(stream);
			htextureInspectionModel.DeserializeTextureInspectionModel(hserializedItem);
			hserializedItem.Dispose();
			return htextureInspectionModel;
		}

		// Token: 0x0600191D RID: 6429 RVA: 0x0009FD42 File Offset: 0x0009DF42
		object ICloneable.Clone()
		{
			return this.Clone();
		}

		// Token: 0x0600191E RID: 6430 RVA: 0x0009FD4C File Offset: 0x0009DF4C
		public new HTextureInspectionModel Clone()
		{
			HSerializedItem hserializedItem = this.SerializeTextureInspectionModel();
			HTextureInspectionModel htextureInspectionModel = new HTextureInspectionModel();
			htextureInspectionModel.DeserializeTextureInspectionModel(hserializedItem);
			hserializedItem.Dispose();
			return htextureInspectionModel;
		}

		/// <summary>
		///   Add training images to the texture inspection model.
		///   Instance represents: Handle of the texture inspection model.
		/// </summary>
		/// <param name="image">Image of flawless texture.</param>
		/// <returns>Indices of the images that have been added to the texture inspection model.</returns>
		// Token: 0x0600191F RID: 6431 RVA: 0x0009FD74 File Offset: 0x0009DF74
		public HTuple AddTextureInspectionModelImage(HImage image)
		{
			IntPtr proc = HalconAPI.PreCall(2043);
			base.Store(proc, 0);
			HalconAPI.Store(proc, 1, image);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			HTuple result;
			num = HTuple.LoadNew(proc, 0, HTupleType.INTEGER, num, out result);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
			GC.KeepAlive(image);
			return result;
		}

		/// <summary>
		///   Inspection of the texture within an image.
		///   Instance represents: Handle of the texture inspection model.
		/// </summary>
		/// <param name="image">Image of the texture to be inspected.</param>
		/// <param name="textureInspectionResultID">Handle of the inspection results.</param>
		/// <returns>Novelty regions.</returns>
		// Token: 0x06001920 RID: 6432 RVA: 0x0009FDCC File Offset: 0x0009DFCC
		public HRegion ApplyTextureInspectionModel(HImage image, out HTextureInspectionResult textureInspectionResultID)
		{
			IntPtr proc = HalconAPI.PreCall(2044);
			base.Store(proc, 0);
			HalconAPI.Store(proc, 1, image);
			HalconAPI.InitOCT(proc, 1);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			HRegion result;
			num = HRegion.LoadNew(proc, 1, num, out result);
			num = HTextureInspectionResult.LoadNew(proc, 0, num, out textureInspectionResultID);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
			GC.KeepAlive(image);
			return result;
		}

		/// <summary>Clear a texture inspection model and free the allocated memory.</summary>
		/// <param name="textureInspectionModel">Handle of the texture inspection model.</param>
		// Token: 0x06001921 RID: 6433 RVA: 0x0009FE34 File Offset: 0x0009E034
		public static void ClearTextureInspectionModel(HTextureInspectionModel[] textureInspectionModel)
		{
			HTuple htuple = HHandleBase.ConcatArray(textureInspectionModel);
			IntPtr proc = HalconAPI.PreCall(2047);
			HalconAPI.Store(proc, 0, htuple);
			int procResult = HalconAPI.CallProcedure(proc);
			HalconAPI.UnpinTuple(htuple);
			HalconAPI.PostCall(proc, procResult);
			GC.KeepAlive(textureInspectionModel);
		}

		/// <summary>
		///   Clear a texture inspection model and free the allocated memory.
		///   Instance represents: Handle of the texture inspection model.
		/// </summary>
		// Token: 0x06001922 RID: 6434 RVA: 0x0009FE78 File Offset: 0x0009E078
		public void ClearTextureInspectionModel()
		{
			IntPtr proc = HalconAPI.PreCall(2047);
			base.Store(proc, 0);
			int procResult = HalconAPI.CallProcedure(proc);
			HalconAPI.PostCall(proc, procResult);
			GC.KeepAlive(this);
		}

		/// <summary>
		///   Create a texture inspection model.
		///   Modified instance represents: Handle for using and accessing the texture inspection model.
		/// </summary>
		/// <param name="modelType">The type of the created texture inspection model. Default: "basic"</param>
		// Token: 0x06001923 RID: 6435 RVA: 0x0009FEAC File Offset: 0x0009E0AC
		public void CreateTextureInspectionModel(string modelType)
		{
			this.Dispose();
			IntPtr proc = HalconAPI.PreCall(2051);
			HalconAPI.StoreS(proc, 0, modelType);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			num = base.Load(proc, 0, num);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
		}

		/// <summary>
		///   Deserialize a serialized texture inspection model.
		///   Modified instance represents: Handle of the texture inspection model.
		/// </summary>
		/// <param name="serializedItemHandle">Handle of the serialized item.</param>
		// Token: 0x06001924 RID: 6436 RVA: 0x0009FEF8 File Offset: 0x0009E0F8
		public void DeserializeTextureInspectionModel(HSerializedItem serializedItemHandle)
		{
			this.Dispose();
			IntPtr proc = HalconAPI.PreCall(2054);
			HalconAPI.Store(proc, 0, serializedItemHandle);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			num = base.Load(proc, 0, num);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
			GC.KeepAlive(serializedItemHandle);
		}

		/// <summary>
		///   Get the training images contained in a texture inspection model.
		///   Instance represents: Handle of the texture inspection model.
		/// </summary>
		/// <returns>Training images contained in the texture inspection model.</returns>
		// Token: 0x06001925 RID: 6437 RVA: 0x0009FF4C File Offset: 0x0009E14C
		public HImage GetTextureInspectionModelImage()
		{
			IntPtr proc = HalconAPI.PreCall(2075);
			base.Store(proc, 0);
			HalconAPI.InitOCT(proc, 1);
			int num = HalconAPI.CallProcedure(proc);
			HImage result;
			num = HImage.LoadNew(proc, 1, num, out result);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
			return result;
		}

		/// <summary>
		///   Query parameters of a texture inspection model.
		///   Instance represents: Handle of the texture inspection model.
		/// </summary>
		/// <param name="genParamName">Name of the queried model parameter. Default: "novelty_threshold"</param>
		/// <returns>Value of the queried model parameter.</returns>
		// Token: 0x06001926 RID: 6438 RVA: 0x0009FF94 File Offset: 0x0009E194
		public HTuple GetTextureInspectionModelParam(HTuple genParamName)
		{
			IntPtr proc = HalconAPI.PreCall(2076);
			base.Store(proc, 0);
			HalconAPI.Store(proc, 1, genParamName);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			HalconAPI.UnpinTuple(genParamName);
			HTuple result;
			num = HTuple.LoadNew(proc, 0, num, out result);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
			return result;
		}

		/// <summary>
		///   Query parameters of a texture inspection model.
		///   Instance represents: Handle of the texture inspection model.
		/// </summary>
		/// <param name="genParamName">Name of the queried model parameter. Default: "novelty_threshold"</param>
		/// <returns>Value of the queried model parameter.</returns>
		// Token: 0x06001927 RID: 6439 RVA: 0x0009FFEC File Offset: 0x0009E1EC
		public HTuple GetTextureInspectionModelParam(string genParamName)
		{
			IntPtr proc = HalconAPI.PreCall(2076);
			base.Store(proc, 0);
			HalconAPI.StoreS(proc, 1, genParamName);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			HTuple result;
			num = HTuple.LoadNew(proc, 0, num, out result);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
			return result;
		}

		/// <summary>
		///   Read a texture inspection model from a file.
		///   Modified instance represents: Handle of the texture inspection model.
		/// </summary>
		/// <param name="fileName">File name.</param>
		// Token: 0x06001928 RID: 6440 RVA: 0x000A003C File Offset: 0x0009E23C
		public void ReadTextureInspectionModel(string fileName)
		{
			this.Dispose();
			IntPtr proc = HalconAPI.PreCall(2083);
			HalconAPI.StoreS(proc, 0, fileName);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			num = base.Load(proc, 0, num);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
		}

		/// <summary>Clear all or a user-defined subset of the images of a texture inspection model.</summary>
		/// <param name="textureInspectionModel">Handle of the texture inspection model.</param>
		/// <param name="indices">Indices of the images to be deleted from the texture inspection model.</param>
		/// <returns>Indices of the images that remain in the texture inspection model.</returns>
		// Token: 0x06001929 RID: 6441 RVA: 0x000A0088 File Offset: 0x0009E288
		public static HTuple RemoveTextureInspectionModelImage(HTextureInspectionModel[] textureInspectionModel, HTuple indices)
		{
			HTuple htuple = HHandleBase.ConcatArray(textureInspectionModel);
			IntPtr proc = HalconAPI.PreCall(2085);
			HalconAPI.Store(proc, 0, htuple);
			HalconAPI.Store(proc, 1, indices);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			HalconAPI.UnpinTuple(htuple);
			HalconAPI.UnpinTuple(indices);
			HTuple result;
			num = HTuple.LoadNew(proc, 0, HTupleType.INTEGER, num, out result);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(textureInspectionModel);
			return result;
		}

		/// <summary>
		///   Clear all or a user-defined subset of the images of a texture inspection model.
		///   Instance represents: Handle of the texture inspection model.
		/// </summary>
		/// <param name="indices">Indices of the images to be deleted from the texture inspection model.</param>
		/// <returns>Indices of the images that remain in the texture inspection model.</returns>
		// Token: 0x0600192A RID: 6442 RVA: 0x000A00EC File Offset: 0x0009E2EC
		public HTuple RemoveTextureInspectionModelImage(HTuple indices)
		{
			IntPtr proc = HalconAPI.PreCall(2085);
			base.Store(proc, 0);
			HalconAPI.Store(proc, 1, indices);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			HalconAPI.UnpinTuple(indices);
			HTuple result;
			num = HTuple.LoadNew(proc, 0, HTupleType.INTEGER, num, out result);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
			return result;
		}

		/// <summary>
		///   Serialize a texture inspection model.
		///   Instance represents: Handle of the texture inspection model.
		/// </summary>
		/// <returns>Handle of the serialized item.</returns>
		// Token: 0x0600192B RID: 6443 RVA: 0x000A0144 File Offset: 0x0009E344
		public HSerializedItem SerializeTextureInspectionModel()
		{
			IntPtr proc = HalconAPI.PreCall(2094);
			base.Store(proc, 0);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			HSerializedItem result;
			num = HSerializedItem.LoadNew(proc, 0, num, out result);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
			return result;
		}

		/// <summary>
		///   Set parameters of a texture inspection model.
		///   Instance represents: Handle of the texture inspection model.
		/// </summary>
		/// <param name="genParamName">Name of the model parameter to be adjusted. Default: "gen_result_handle"</param>
		/// <param name="genParamValue">New value of the model parameter. Default: "true"</param>
		// Token: 0x0600192C RID: 6444 RVA: 0x000A018C File Offset: 0x0009E38C
		public void SetTextureInspectionModelParam(HTuple genParamName, HTuple genParamValue)
		{
			IntPtr proc = HalconAPI.PreCall(2098);
			base.Store(proc, 0);
			HalconAPI.Store(proc, 1, genParamName);
			HalconAPI.Store(proc, 2, genParamValue);
			int procResult = HalconAPI.CallProcedure(proc);
			HalconAPI.UnpinTuple(genParamName);
			HalconAPI.UnpinTuple(genParamValue);
			HalconAPI.PostCall(proc, procResult);
			GC.KeepAlive(this);
		}

		/// <summary>
		///   Set parameters of a texture inspection model.
		///   Instance represents: Handle of the texture inspection model.
		/// </summary>
		/// <param name="genParamName">Name of the model parameter to be adjusted. Default: "gen_result_handle"</param>
		/// <param name="genParamValue">New value of the model parameter. Default: "true"</param>
		// Token: 0x0600192D RID: 6445 RVA: 0x000A01DC File Offset: 0x0009E3DC
		public void SetTextureInspectionModelParam(string genParamName, int genParamValue)
		{
			IntPtr proc = HalconAPI.PreCall(2098);
			base.Store(proc, 0);
			HalconAPI.StoreS(proc, 1, genParamName);
			HalconAPI.StoreI(proc, 2, genParamValue);
			int procResult = HalconAPI.CallProcedure(proc);
			HalconAPI.PostCall(proc, procResult);
			GC.KeepAlive(this);
		}

		/// <summary>
		///   Train a texture inspection model.
		///   Instance represents: Handle of the texture inspection model.
		/// </summary>
		// Token: 0x0600192E RID: 6446 RVA: 0x000A0220 File Offset: 0x0009E420
		public void TrainTextureInspectionModel()
		{
			IntPtr proc = HalconAPI.PreCall(2099);
			base.Store(proc, 0);
			int procResult = HalconAPI.CallProcedure(proc);
			HalconAPI.PostCall(proc, procResult);
			GC.KeepAlive(this);
		}

		/// <summary>
		///   Write a texture inspection model to a file.
		///   Instance represents: Handle of the texture inspection model.
		/// </summary>
		/// <param name="fileName">File name.</param>
		// Token: 0x0600192F RID: 6447 RVA: 0x000A0254 File Offset: 0x0009E454
		public void WriteTextureInspectionModel(string fileName)
		{
			IntPtr proc = HalconAPI.PreCall(2100);
			base.Store(proc, 0);
			HalconAPI.StoreS(proc, 1, fileName);
			int procResult = HalconAPI.CallProcedure(proc);
			HalconAPI.PostCall(proc, procResult);
			GC.KeepAlive(this);
		}
	}
}
